(library (grid-gen Einfeldt)

(export Einfeldt:lam)

(import (guile)
        (grid-gen main)
        (grid-gen math)
)

(define Einfeldt:lam (lambda (d)
    (lambda (vm)
      (let* ((cr  (arr-elements ((PHYS:chrs d) vm)))
             (crl (arr-elements ((PHYS:chrs d) (vm 'vl))))
             (crr (arr-elements ((PHYS:chrs d) (vm 'vr))))
             (u (list-ref '(u v w) d))
            )
        (abs2
          (math-cvector
           `(if (>= ,(vm u) 0.0)
                (min ,(list-ref cr 0) ,(list-ref crl 0))
               ,(list-ref cr 0)
            )
            (list-ref cr 1)
            (list-ref cr 2)
            (list-ref cr 3)
           `(if (<= ,(vm u) 0.0)
                (max ,(list-ref cr 4) ,(list-ref crr 4))
               ,(list-ref cr 4)
            )
          )
        )
      )
    )
))

)

(import (grid-gen main))
(set! ADV:lam Einfeldt:lam)
